<template>
  <div>登录成功，正在返回...</div>
</template>
<script>

import Oidc from "oidc-client";

const mgr = new Oidc.UserManager({ userStore: new Oidc.WebStorageStateStore(), loadUserInfo: true, filterProtocolClaims: true });

export default {
  name: "SigninOidc",
  data() {
    return {
      redirect: undefined,
      mgr: mgr
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  created() {
    this.mgr
      .signinRedirectCallback()
      .then(user => {                
        this.$store.dispatch('auth/addToken', user).then(() => {
          this.$store.dispatch('app/configuration').then(() => {
            this.$router.push({ path: this.redirect || '/' })
          }).catch((result) => {
            console.log('error', result);
          });
        })
      })
      .catch(err => {
        console.log(err);
      });
  }
};
</script>
